package com.nan.mybatisplus.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @Title: mybatisplus
 * @escription: this is a MyMetaObjectandler Class
 * @Author: Mr.Nan
 * @Version: 1.0 2021-10-11 10:06
 **/

//自动填充策略
@Slf4j
@Component
public class MyMetaObjectandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("start insert fill.......");
        // 字段  值  类
        this.setFieldValByName("createTime", new Date(), metaObject);
        this.setFieldValByName("updateTime", new Date(), metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("start update fill.......");
        this.setFieldValByName("updateTime", new Date(), metaObject);
    }
}
